package modelo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;


public class FraseDAO {

	public FraseDAO() {
		super(); 
	}

	public void registrarFrase(Frase frase){
		String tiraSQL = "INSERT INTO frase"+
						"(idfrase, descripcion, nivel) "+
						"VALUES("+
						""+frase.getidFrase()+", '"+frase.getDescripcion()+
		 				 "', "+frase.getNivel().getIdnivel()+" )";
		Conexion.ejecutar(tiraSQL);
	}
	
	public 	Vector<String> leerFrase(int nivel){
		Vector<String> vectorFrases = new Vector<String>();
		String tiraSQL = "SELECT descripcion FROM frase WHERE nivel='"+nivel+"'";
		ResultSet resultSet = Conexion.consultar(tiraSQL);
		try{
			while( resultSet.next() ){
				String descripcion = resultSet.getString("descripcion");
				
				vectorFrases.add(descripcion);	
			}
		}
		catch(SQLException e) {
			e.printStackTrace();
		}
		return vectorFrases;
	}
	
	public int generarNumeroFrase(){
		int numero=0;
		String tiraSQL = "SELECT count(idfrase) AS cuantos FROM frase";
		ResultSet resultSet = Conexion.consultar(tiraSQL);
		try{
			if(resultSet.next()){
				numero = resultSet.getInt("cuantos");
			}
		}
		catch(SQLException e){
			e.printStackTrace();
		}
		return numero+1;
	}

}
